#include "as_luavm.h"
#include "as_luavar.h"
#include "log.h"
#include "time_value.h"

#ifdef AS_LUA

as::tools::LuaVm::LuaVm()
{
	L = luaL_newstate();
	Register(L);
}

as::tools::LuaVm::~LuaVm()
{
	lua_close(L);
	L = nullptr;
}

void as::tools::LuaVm::Register(lua_State *L)
{
	luaL_openlibs(L);
	lua_createtable(L, 0, 1);
	lua_pushcfunction(L, [](lua_State *L)
		{
			lua_pushnumber(L, TimeValue::GetMsTime());
			return 1;
		}
	);
	lua_setfield(L, -2, "GetMsTime");
	lua_setglobal(L, "as");

	LuaVar::Register(L);
}


#endif
